package com.wc.算法基础课.C第三讲搜索与图论.Dijkstra.通信线路;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

/**
 * @Author congge
 * @Date 2024/4/15 22:44
 * @description https://www.acwing.com/problem/content/description/342/
 */
public class Main {
    /**
     * 题意理解错误，以为是k个免费的券呢
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 1010, M = 20010;
    // dist[i][j] 表示到达i用了j个券
    static long[][] dist = new long[N][N];
    static int[] maxV = new int[N];
    static long INF = (long) 1e11;
    static int[] h = new int[N], e = new int[M], ne = new int[M], w = new int[M];
    static int idx = 1;
    static int n, m, k;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        k = sc.nextInt();
        while (m-- > 0) {
            int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt();
            add(a, b, c);
            add(b, a, c);
        }
        long res = dijkstra();
        out.println(res);
        out.flush();
    }

    static void add(int a, int b, int c) {
        e[idx] = b;
        w[idx] = c;
        ne[idx] = h[a];
        h[a] = idx++;
    }

    static long dijkstra() {
        for (int i = 1; i <= n; i++) {
            Arrays.fill(dist[i], 0, k + 1, INF);
            maxV[i] = -1;
        }
        PriorityQueue<long[]> q = new PriorityQueue<>(Comparator.comparingLong(o -> o[0]));
        dist[1][0] = 0;
        // 第一个是价格,第二个是编号,第三个是券
        q.add(new long[]{0, 1, 0});
        while (!q.isEmpty()) {
            long[] a = q.poll();
            int t = (int) a[1];
            int pp = (int) a[2];
            for (int i = h[t]; i > 0; i = ne[i]) {
                int j = e[i];
                // 不用券
                if (dist[j][pp] > dist[t][pp] + w[i]) {
                    dist[j][pp] = dist[t][pp] + w[i];
                    q.add(new long[]{dist[j][pp], j, pp});
                }
                // 用券
                if (pp < k && dist[j][pp + 1] > dist[t][pp]) {
                    dist[j][pp + 1] = dist[t][pp];
                    q.add(new long[]{dist[j][pp + 1], j, pp + 1});
                }
            }
        }
        long res = INF;
        for(int i = 0; i <= k; i++) res = Math.min(res, dist[n][i]);
        return res == INF ? -1 : res;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
